package com.lantosec.hmrp.modules.morality.controller;


import com.lantosec.hmrp.core.kit.PageVO;
import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import com.lantosec.hmrp.modules.morality.entity.MoralityNoteList;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.morality.entity.MoralityNote;
import com.lantosec.hmrp.modules.morality.service.IMoralityNoteService;
import com.lantosec.hmrp.modules.morality.vo.MoralityNoteVO;

import java.util.Arrays;
import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 *
 * 考评记录 控制器
 *
 * @author AutoCode
 * @since 2020-04-20
 */
@Api(value = "考评记录控制器", tags = "考评记录控制器")
@RestController
@RequestMapping("/morality/note")
@Log4j2
public class MoralityNoteController extends BaseController {
    @Autowired
    private IMoralityNoteService service;

    @GetMapping("all")
    @ApiOperation(value = "查询全部")
    public Result<List<MoralityNoteVO>> all(){
        return Result.ok(entity2VO(service.list()));
    }

    @GetMapping("page")
    @ApiOperation(value = "个人自评分页查询")
    public Result<PageVO<MoralityNoteVO>> page(@ApiParam(value = "分页对象", required = true) PageVO<MoralityNoteVO> page,
                                               @ApiParam(value = "审核环节") @RequestParam(name = "state",required = false) Integer state,
                                               @ApiParam(value = "考评方案名称") @RequestParam(name = "moralityPlanName", required = false) String moralityPlanName){
         service.getAll(page,state,moralityPlanName);
        return Result.ok(page);
    }

    @GetMapping("getDeptNotExamine")
    @ApiOperation(value = "科室审核列表")
    public Result<PageVO<MoralityNoteVO>> getDeptNotExamine(@ApiParam(value = "分页对象", required = true) PageVO<MoralityNoteVO> page,
                                                            @ApiParam(value = "姓名") @RequestParam(name = "userName", required = false) String userName,
                                                            @ApiParam(value = "考评方案名称") @RequestParam(name = "moralityPlanName", required = false) String moralityPlanName){
        service.getDeptNotExamine(page,userName,moralityPlanName);
        return Result.ok(page);
    }

    @GetMapping("getDeptExamineDoc")
    @ApiOperation(value = "科室审核列表(医生)")
    public Result<PageVO<MoralityNoteVO>> getDeptExamineDoc(@ApiParam(value = "分页对象", required = true) PageVO<MoralityNoteVO> page){
        service.getDeptExamineDoc(page);
        return Result.ok(page);
    }

    @GetMapping("getDeptExamineNur")
    @ApiOperation(value = "科室审核列表(护士)")
    public Result<PageVO<MoralityNoteVO>> getDeptExamineNur(@ApiParam(value = "分页对象", required = true) PageVO<MoralityNoteVO> page){
        service.getDeptExamineNur(page);
        return Result.ok(page);
    }

    @GetMapping("getPartyBranchExamine")
    @ApiOperation(value = "党支部审核列表")
    public Result<PageVO<MoralityNoteVO>> getPartyBranchExamine(@ApiParam(value = "分页对象", required = true) PageVO<MoralityNoteVO> page,
                                                                @ApiParam(value = "姓名") @RequestParam(name = "userName", required = false) String userName,
                                                                @ApiParam(value = "部门ID") @RequestParam(name = "deptId", required = false) String deptId,
                                                                @ApiParam(value = "考评方案名称") @RequestParam(name = "moralityPlanName", required = false) String moralityPlanName){
        service.getPartyBranchExamine(page,userName,deptId,moralityPlanName);
        return Result.ok(page);
    }

    @GetMapping("getAppraisalExamine")
    @ApiOperation(value = "考评委员会审核列表")
    public Result<PageVO<MoralityNoteVO>> getAppraisalExamine(@ApiParam(value = "分页对象", required = true) PageVO<MoralityNoteVO> page,
                                                              @ApiParam(value = "姓名") @RequestParam(name = "userName", required = false) String userName,
                                                              @ApiParam(value = "部门ID") @RequestParam(name = "deptId", required = false) String deptId,
                                                              @ApiParam(value = "考评方案名称") @RequestParam(name = "moralityPlanName", required = false) String moralityPlanName){
        service.getAppraisalExamine(page,userName,deptId,moralityPlanName);
        return Result.ok(page);
    }

    @PutMapping("update")
    @ControllerLog(name = "个人自评修改提交", type = LogType.update)
    @ApiOperation(value = "个人自评修改提交")
    public Result<Void> update(@ApiParam(value = "考评记录VO对象", required = true) @RequestBody MoralityNoteList moralityNoteList){
        service.updateMoralityNote(moralityNoteList);
        return Result.ok();
    }

    @PutMapping("deptExamineCommit")
    @ControllerLog(name = "科室审核提交", type = LogType.update)
    @ApiOperation(value = "科室审核提交")
    public Result<Void> deptExamineCommit(@ApiParam(value = "考评记录VO对象", required = true) @RequestBody MoralityNoteList moralityNoteList){
        service.deptExamineCommit(moralityNoteList);
        return Result.ok();
    }

    @PutMapping("deptExamineListCommit")
    @ControllerLog(name = "科室列表审核提交", type = LogType.update)
    @ApiOperation(value = "科室列表审核提交")
    public Result<Void> deptExamineListCommit(@ApiParam(value = "考评记录VO对象", required = true) @RequestBody List<MoralityNote> moralityNotes){
        service.deptExamineListCommit(moralityNotes);
        return Result.ok();
    }

}
